package cn.stylefeng.guns.modular.common.contorller;

import cn.stylefeng.guns.modular.common.service.CommonService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@ApiResource(name = "共通")
public class CommonController {
    @Resource
    CommonService commonService;

    @GetResource(name = "获取组织列表", path = "/common/getOrgids")
    public ResponseData<List<Map>> getOrgids() {
        return new SuccessResponseData<>(commonService.getOrgids());
    }

    @GetResource(name = "获取组织列表", path = "/common/getTreeOrgids")
    public ResponseData<List<Map>> getTreeOrgids() {
        return new SuccessResponseData<>(commonService.getTreeOrgids());
    }

    @GetResource(name = "获取设备类型列表", path = "/common/getEqpTypeList")
    public ResponseData<List<Map>> getEqpTypeList() {
        List<Map> eqpTypeList = commonService.getEqpTypeList();
        if (eqpTypeList == null || eqpTypeList.size() == 0) {
            return new ErrorResponseData<List<Map>>("500", "设备类型列表为空");
        }
        return new SuccessResponseData<>(eqpTypeList);
    }

    @GetResource(name = "获取工位列表", path = "/common/getStation")
    public ResponseData<List<Map>> getStation() {
        List<Map> stationList = commonService.getStation();
        if (stationList == null || stationList.size() == 0) {
            return new ErrorResponseData<List<Map>>("500", "工位列表为空");
        }
        return new SuccessResponseData<>(stationList);
    }

    @GetResource(name = "获取产品列表", path = "/common/getItemList")
    public ResponseData<List<Map>> getItemList() {
        List<Map> stationList = commonService.getItemList();
        if (stationList == null || stationList.size() == 0) {
            return new ErrorResponseData<List<Map>>("500", "产品列表为空");
        }
        return new SuccessResponseData<>(stationList);
    }

    @GetResource(name = "获取途程列表", path = "/common/getRouteList")
    public ResponseData<List<Map>> getRouteList() {
        List<Map> stationList = commonService.getRouteList();
        if (stationList == null || stationList.size() == 0) {
            return new ErrorResponseData<List<Map>>("500", "途程列表为空");
        }
        return new SuccessResponseData<>(stationList);
    }
}
